/**
 * @file exti_bsp.c
 * @author  xiaowine (xiaowine@sina.cn)
 * @brief
 * @version 01.00
 * @date    2022-03-25
 *
 * @copyright Copyright (c) {2020}  xiaowine
 *
 * @par 修改日志:
 * <table>
 * <tr><th>Date       <th>Version <th>Author  <th>Description
 * <tr><td>2022-03-25 <td>1.0     <td>wangh     <td>内容
 * </table>
 * ******************************************************************
 * *                   .::::
 * *                 .::::::::
 * *                ::::::::::
 * *             ..:::::::::::
 * *          '::::::::::::
 * *            .:::::::::
 * *       '::::::::::::::..        女神助攻,流量冲天
 * *            ..::::::::::::.     永不宕机,代码无bug
 * *          ``:::::::::::::::
 * *           ::::``:::::::::'        .:::
 * *          ::::'   ':::::'       .::::::::
 * *        .::::'      ::::     .:::::::'::::
 * *       .:::'       :::::  .:::::::::' ':::::
 * *      .::'        :::::.:::::::::'      ':::::
 * *     .::'         ::::::::::::::'         ``::::
 * * ...:::           ::::::::::::'              ``::
 * *```` ':.          ':::::::::'                  ::::.
 * *                   '.:::::'                    ':'````.
 * ******************************************************************
 */
/* Private includes ----------------------------------------------------------*/

#include "exti_bsp.h"
/* Private typedef -----------------------------------------------------------*/

/* Private define ------------------------------------------------------------*/

/* Private macro -------------------------------------------------------------*/

/* Private variables ---------------------------------------------------------*/
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;

/* Public variables ----------------------------------------------------------*/

/* Private function prototypes -----------------------------------------------*/

/* Private functions ---------------------------------------------------------*/

/* Private user code ---------------------------------------------------------*/

//外部中断0服务程序
void EXTIX_Init(void)
{
    // EXTI_InitTypeDef EXTI_InitStructure;
    // NVIC_InitTypeDef NVIC_InitStructure;
    GPIO_InitTypeDef GPIO_InitStructure;

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);  //使能复用功能时钟

    // IO初始化
    GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_6;     //返回电平引脚
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;  //上拉输入
    GPIO_Init(GPIOB, &GPIO_InitStructure);

    // GPIOB.6 中断线以及中断初始化配置   下降沿触发
    GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource6);

    EXTI_InitStructure.EXTI_Line    = EXTI_Line6;
    EXTI_InitStructure.EXTI_Mode    = EXTI_Mode_Interrupt;
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
    EXTI_InitStructure.EXTI_LineCmd = ENABLE;
    EXTI_Init(&EXTI_InitStructure);  //根据EXTI_InitStruct中指定的参数初始化外设EXTI寄存器

    NVIC_InitStructure.NVIC_IRQChannel                   = EXTI9_5_IRQn;  //使能按键KEY2所在的外部中断通道
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02;          //抢占优先级2，
    NVIC_InitStructure.NVIC_IRQChannelSubPriority        = 0x00;          //子优先级2
    NVIC_InitStructure.NVIC_IRQChannelCmd                = ENABLE;        //使能外部中断通道
    NVIC_Init(&NVIC_InitStructure);
}

//
void Exti_Enable(void)
{
    NVIC_InitStructure.NVIC_IRQChannel                   = EXTI9_5_IRQn;  //使能按键KEY2所在的外部中断通道
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02;          //抢占优先级2，
    NVIC_InitStructure.NVIC_IRQChannelSubPriority        = 0x00;          //子优先级2
    NVIC_InitStructure.NVIC_IRQChannelCmd                = ENABLE;        //使能外部中断通道
    NVIC_Init(&NVIC_InitStructure);
}

void Exti_Disable(void)
{
    NVIC_InitStructure.NVIC_IRQChannel                   = EXTI9_5_IRQn;  //使能按键KEY2所在的外部中断通道
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02;          //抢占优先级2，
    NVIC_InitStructure.NVIC_IRQChannelSubPriority        = 0x00;          //子优先级2
    NVIC_InitStructure.NVIC_IRQChannelCmd                = DISABLE;       //使能外部中断通道
    NVIC_Init(&NVIC_InitStructure);
}
